<!DOCTYPE html>
<html lang="en">
	<?php $this->load->view('vheader');?>
	<body>
		<?php $this->load->view('vnavbar'); ?>
		<div class="main-container" id="main-container">
			<script type="text/javascript">
				try{ace.settings.check('main-container' , 'fixed')}catch(e){}
			</script>

			<div class="main-container-inner">
				<a class="menu-toggler" id="menu-toggler" href="#">
					<span class="menu-text"></span>
				</a>

				<?php $this->load->view('vsidebar'); ?>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<script type="text/javascript">
							try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
						</script>

						<ul class="breadcrumb">
							<li>
								<i class="icon-home home-icon"></i>
								<a href="#">Tambah User</a>
							</li>
							<!--
							<li class="active">Dashboard</li>
							-->
						</ul><!-- .breadcrumb -->

						<div class="nav-search" id="nav-search">
							<!--
							<form class="form-search">
								<span class="input-icon">
									<input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
									<i class="icon-search nav-search-icon"></i>
								</span>
							</form>
							-->
						</div><!-- #nav-search -->
					</div>

					<div class="page-content">
						
						<div class="page-header">
							<h1>
								Tambah User
								<!--
								<small>
									<i class="icon-double-angle-right"></i>
									overview &amp; stats
								</small>
								-->
							</h1>
						</div><!-- /.page-header -->
						
						<form id="forminputdata" class="form-horizontal" role="form" method="post">
						<?php if ($this->uri->segment(3) == 'y'){ ?>
							<div class="alert alert-block alert-success">
								<button data-dismiss="alert" class="close" type="button">
									<i class="icon-remove"></i>
								</button>
						
								<p>
									<strong>
										<i class="icon-ok"></i>
										Penyimpanan Data Berhasil!
									</strong>
									Anda telah berhasil menambahkan data user, silakan menambahkan data user lainnya
								</p>
						
							</div>
						<?php } ?>
						<div class="col-xs-12">
							<div id="recent-box" class="widget-box transparent">
						
								<div class="widget-body">
									<div class="widget-main padding-4">
										<div class="tab-content padding-8 overflow-visible">
											<div class="space-4"></div>
											<div class="form-group">
												<label class="col-sm-3 control-label no-padding-right" for="username"> Nama User </label>
											
												<div class="col-sm-9">
													<input type="text" name="username" id="username" placeholder="Nama User" class="col-xs-10 col-sm-5" />
												</div>
											</div>

											<div class="space-4"></div>
											<div class="form-group">
												<label class="col-sm-3 control-label no-padding-right" for="password"> Password </label>
											
												<div class="col-sm-9">
													<input type="password" name="password" id="password" placeholder="Password" class="col-xs-10 col-sm-5"  />

												</div>
											</div>

											<div class="space-4"></div>
											<div class="form-group">
												<label class="col-sm-3 control-label no-padding-right" for="password2"> Ulangi Password </label>
											
												<div class="col-sm-9">
													<input type="password" name="password2" id="password2" placeholder="Ulangi Password" class="col-xs-10 col-sm-5"  />

												</div>
											</div>
									
											<div class="space-4"></div>						
											<div class="form-group">
												<label class="col-sm-3 control-label no-padding-right" for="ref_role"> Role User </label>
											
												<div class="col-sm-3">
													<select id="ref_role" name="ref_role" class="form-control" >		
														<?php $role = $queryrole->result();foreach ($role as $row) { ?>
															<option value="<?= $row->id ?>"> <?= $row->detil ?>  </option>
														<?php } ?>
													</select>
												</div>
											</div>		            

											<div class="space-4"></div>						
											<div id="input_provinsi" class="form-group">
												<label class="col-sm-3 control-label no-padding-right" for="id_kota"> Provinsi </label>
											
												<div class="col-sm-3">
													<select id="id_provinsi" name="id_provinsi" class="form-control" >	
														<option value="0"> Pilih Provinsi...  </option>	
														<?php $kota = $queryprovinsi->result();foreach ($kota as $row) { ?>
															<option value="<?= $row->id_provinsi ?>"> <?= $row->nama_provinsi ?>  </option>
														<?php } ?>
													</select>
												</div>
											</div>		            

											<div class="space-4"></div>						
											<div id="input_cabang" class="form-group">
												<label class="col-sm-3 control-label no-padding-right" for="id_kota"> Kantor Cabang </label>
											
												<div class="col-sm-3">
													<select id="id_kota" name="id_kota" class="form-control" >	
														<option value="0"> Pilih Cabang...  </option>	
														<?php $kota = $querycabang->result();foreach ($kota as $row) { ?>
															<option value="<?= $row->id_kota ?>"> <?= $row->nama_kota ?>  </option>
														<?php } ?>
													</select>
												</div>
											</div>		            
											
											<div class="space-4"></div>
											<div id="input_customer" class="form-group">
												<label class="col-sm-3 control-label no-padding-right" for="id_customer"> Customer  </label>
											
												<div class="col-sm-3">
													<select id="id_customer" name="id_customer" class="form-control"  >		
														<option value="0"> Pilih Customer...  </option>
														<?php $customer = $querycustomer->result();foreach ($customer as $row) { ?>
															<option value="<?= $row->id_customer ?>"> <?= $row->nama_customer ?>  </option>
														<?php } ?>
													</select>
												</div>
											</div>
			
										</div>
									</div><!-- /widget-main -->
								</div><!-- /widget-body -->
							</div><!-- /widget-box -->
						</div>
						<!--<form id="formsimpandata" action="<?= site_url() ?>/home/fPSaveData">-->
						<div class="col-xs-12">
							<div class="clearfix form-actions">
								<div class="col-md-offset-3 col-md-9">
									<button id="simpan" class="btn btn-info" type="submit">
										<i class="icon-ok bigger-110"></i>
										Simpan
									</button>  
									<!--	
									&nbsp; &nbsp; &nbsp;
									<button class="btn" type="reset">
										<i class="icon-undo bigger-110"></i>
										Reset
									</button>
									-->
								</div>
							</div>
						</div>


					</div><!-- /.page-content -->
				</div><!-- /.main-content -->

				<!--
				<div class="ace-settings-container" id="ace-settings-container">
					<div class="btn btn-app btn-xs btn-warning ace-settings-btn" id="ace-settings-btn">
						<i class="icon-cog bigger-150"></i>
					</div>
					<div class="ace-settings-box" id="ace-settings-box">
						<div>
							<div class="pull-left">
								<select id="skin-colorpicker" class="hide">
									<option data-skin="default" value="#438EB9">#438EB9</option>
									<option data-skin="skin-1" value="#222A2D">#222A2D</option>
									<option data-skin="skin-2" value="#C6487E">#C6487E</option>
									<option data-skin="skin-3" value="#D0D0D0">#D0D0D0</option>
								</select>
							</div>
							<span>&nbsp; Choose Skin</span>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-navbar" />
							<label class="lbl" for="ace-settings-navbar"> Fixed Navbar</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-sidebar" />
							<label class="lbl" for="ace-settings-sidebar"> Fixed Sidebar</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-breadcrumbs" />
							<label class="lbl" for="ace-settings-breadcrumbs"> Fixed Breadcrumbs</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-rtl" />
							<label class="lbl" for="ace-settings-rtl"> Right To Left (rtl)</label>
						</div>

						<div>
							<input type="checkbox" class="ace ace-checkbox-2" id="ace-settings-add-container" />
							<label class="lbl" for="ace-settings-add-container">
								Inside
								<b>.container</b>
							</label>
						</div>
					</div>
				</div>--><!-- /#ace-settings-container -->
			<!--</div>--><!-- /.main-container-inner -->

			<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
				<i class="icon-double-angle-up icon-only bigger-110"></i>
			</a>
		</div><!-- /.main-container -->

		<!-- basic scripts -->

		<!--[if !IE]> -->

		<script type="text/javascript">
			window.jQuery || document.write("<script src='<?= base_url() ?>assets/js/jquery-2.0.3.min.js'>"+"<"+"/script>");
		</script>

		<!-- <![endif]-->

		<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='<?= base_url() ?>assets/js/jquery-1.10.2.min.js'>"+"<"+"/script>");
</script>
<![endif]-->

		<!-- inline scripts related to this page -->

		<script type="text/javascript">
			jQuery(function($) {	
			});
		</script>
		<script type="text/javascript">
				$(document).ready(function(){
                	$('#ref_role').change(function(){
                		var id_role= $("#ref_role").val();
                		if((id_role == 1) || (id_role == 3))
                		{
                			document.getElementById("input_cabang").style.visibility="hidden";
                			document.getElementById("input_customer").style.visibility="hidden";
                			document.getElementById("input_provinsi").style.visibility="hidden";
                		}
                		else if(id_role == 2)
                		{
                			document.getElementById("input_customer").style.visibility="hidden";
                			document.getElementById("input_cabang").style.visibility="visible";
                			document.getElementById("input_provinsi").style.visibility="visible";
                		}
                		else if(id_role == 4)
                		{
                			document.getElementById("input_customer").style.visibility="hidden";
                			document.getElementById("input_cabang").style.visibility="hidden";
                			document.getElementById("input_provinsi").style.visibility="visible";
                		}
                		else if(id_role == 5)
                		{
                			document.getElementById("input_cabang").style.visibility="hidden";
                			document.getElementById("input_customer").style.visibility="visible";
                			document.getElementById("input_provinsi").style.visibility="hidden";
                		}			
                		else if(id_role == 6)
                		{
                			document.getElementById("input_cabang").style.visibility="hidden";
                			document.getElementById("input_customer").style.visibility="hidden";
                			document.getElementById("input_provinsi").style.visibility="hidden";
                		}			
                    });
                    $("#simpan").click(function(){
                    	var username=$("#username").val();
                    	var ref_role=$("#ref_role").val();
                    	var id_provinsi=$("#id_provinsi").val();
                    	var id_kota=$("#id_kota").val();
                    	var id_customer=$("#id_customer").val();
                    	var password=$("#password").val();
                    	var password2=$("#password2").val();                   	
                    	var dataString = 'username='+username+'&ref_role='+ref_role+'&id_provinsi='+id_provinsi+'&id_kota='+id_kota+'&id_customer='+id_customer+'&password='+password;                                    
                  		if((username == '') || (password == ''))
                    	{
                    		alert("Silakan isi data dengan lengkap");
                    	}
                    	else if(password != password2)
                    		alert("Pasword yang dimasukkan tidak sama");
                    	else if(((ref_role==2)&&(id_kota==0))
                    			|| ((ref_role==5)&&(id_customer==0))
                    			|| ((ref_role==4)&&(id_provinsi==0)))
                    		alert("Silakan isi data dengan lengkap");
                    	else
                    	{
                    		$.ajax({
                    			type: "POST",
                    			url:siteUrl+'/user/dotambahuser',
                    			data: dataString,
                    			cache: false,
                    			success: function(result){
                         			window.location = siteUrl+"/user";
                    			}
                    		});
                    	}
                    
                    	return false;
                 
                	});	
         			
         			$('#id_provinsi').change(function() {
               			//  alert("#aa");
                		$.post("<?php echo site_url(); ?>/user/get_kabupatenkota/"+ $('#id_provinsi').val(), {}, function(obj) {
                    		$('#id_kota').html(obj);
                
               	 		});
                	});
                				
                });
		</script>
		<script type="text/javascript">
				document.getElementById('id_kota').value="0";
				document.getElementById('id_customer').value="0";
               	document.getElementById("input_cabang").style.visibility="hidden";
                document.getElementById("input_customer").style.visibility="hidden";
                document.getElementById("input_provinsi").style.visibility="hidden";
		</script>		
	</body>
</html>
